<?php
/**
 * PrynLib
 * @copyright 2007-2009 Prynel
 * @author Olivier ROGER <roger.olivier@gmail.com>
 * @category libPrynel
 * @package Form
 * @version $Revision: 80 $
 */

/**
 * Element DatePicker. Champs date avec selection JS de la date.
 * Requiert l'inclusion de datepicker.js, prototype.js et prototype-date-extensions.js
 * 
 * @category libPrynel
 * @package Form
 * @subpackage Form_Element
 * @version 1.0.0 
 * @author Olivier ROGER <roger.olivier@gmail.com>
 * @copyright  2007-2009 Prynel
 *       
 *
 */
class Form_Element_DatePicker extends Form_Element_Date
{
	private $icon;
	private $timePicker;
	private $timePickerOnSide;
	
	/**
	 * Constructeur. Par défaut image struct/picto/cal.gif et pas de séléction de l'heure
	 *
	 * @param string $nom
	 * @param Form_Form $form
	 * @access public
	 */
	public function __construct($nom,$form)
	{
		parent::__construct($nom,$form);
		$this->attrs['id'] = $nom;
		$this->icon = 'struct/picto/cal.gif';
		$this->timePicker = false;
	}
	
	/**
	 * Défini l'icone illustrant la date
	 *
	 * @param string $icon Chemin vers l'icone
	 * @access public
	 * @return Form_Element_DatePicker
	 */
	public function icon($icon)
	{
		$this->icon = $icon;
		return $this;
	}
	
	/**
	 * Défini l'affichage ou non du timepicker en plus de la date
	 *
	 * @param boolean $bool
	 * @access public
	 * @return Form_Element_DatePicker
	 */
	public function timePicker($bool=true)
	{
		$this->timePicker = $bool;
		return $this;
	}
	
	/**
	 * Place le time picker sur le coté plutot qu'en dessous
	 *
	 * @param boolean $bool
	 * @access public
	 * @return Form_Element_DatePicker
	 */
	public function putTimePickerOnSide($bool=true)
	{
		$this->timePickerOnSide = $bool;
		return $this;
	}
	
	/**
	 * Ecriture de l'objet
	 *
	 * @access public
	 * @return string
	 */
	public function __toString()
	{
		$timepicker = '';
		$timepickerside = '';
		if($this->timePicker)
			$timepicker = ',timePicker: true';
		if($this->timePickerOnSide)
			$timepickerside = ',timePickerAdjacent: true';
		$field = parent::__toString();
		$field.="\t".'<script type="text/javascript">'."\n";
		$field.="\t\t".'var dateP = new Control.DatePicker(\''.$this->attrs['id'].'\',{icon:\''.$this->icon.'\',locale:\''.$this->format.'\''.$timepicker.$timepickerside.'});'."\n";
		$field.="\t".'</script>'."\n";
		$error = '';
		return $field;
	}
}
 ?>